<?php

$version = 0.71;

//****************************************************
//                                                   *
// This is the CGI back-end for the Aero-Matic gen-  *
// erator. The front-end is aeromatic.html.          *
//                                                   *
// July 2003, David P. Culp, davidculp2@comcast.net  *
//                                                   * 
//****************************************************

header("Content-type: text/plain");


//***** GET DATA FROM USER ***************************

$ac_enginepower     = $_POST['ac_enginepower'];
$ac_engineunits     = $_POST['ac_engineunits'];
$ac_pitch           = $_POST['ac_prop_pitch'];

//***** CONVERT TO ENGLISH UNITS *********************

if($ac_engineunits == 1) {
  $ac_enginepower *= 1.341;
  }



//************************************************
//*                                              *
//*  Print out xml document                      *
//*                                              *
//************************************************

// estimate total linear-blade-inches from horsepower

$LBI = 5.3 * pow($ac_enginepower, 0.5);

// estimate number of blades and diameter from horsepower

if($ac_enginepower < 400) {
  $blades = 2;
  $dia = $LBI;
  }
elseif($ac_enginepower < 1400) {
  $blades = 3;
  $dia = $LBI * 0.666667; 
  }
else {
  $blades = 4;
  $dia = $LBI * 0.5;
  }
$dia = 75.0;

// estimate moment of inertia

$L = $dia / 24;          // length each blade (feet)
$M = $L * 0.09317;       // mass each blade (slugs)
$ixx = $blades * (0.33333 * $M * $L * $L);

//*****************************************************
//                                                    *
//  Print XML file                                    *
//                                                    *
//*****************************************************

print("<?xml version=\"1.0\"?>\n");
print("<!-- Generated by Aero-Matic v $version\n\n");
print("     Inputs:\n"); 
print("       horsepower:   $ac_enginepower\n");
if($ac_pitch == 0)
  print("       pitch:        fixed\n");
else
  print("       pitch:        variable\n\n");
print("     Outputs:\n");
print("       linear-blade-inches: $LBI\n");
print("-->\n\n");

print("<FG_PROPELLER NAME=\"prop\">\n");
print("  IXX        $ixx\n");
print("  DIAMETER   $dia\n");
print("  NUMBLADES  $blades\n");
if($ac_pitch == 0) {
  print("  MINPITCH   30\n");
 } else {
  print("  MINPITCH   10\n");
 }
print("  MAXPITCH   30\n");
print("  MINRPM    700\n");
print("  MAXRPM   2700\n");

if($ac_pitch == 0) {          // fixed pitch
print("  C_THRUST   11 1\n");
print("  0.0  0.0936\n");
print("  0.1  0.0927\n");
print("  0.2  0.0918\n");
print("  0.3  0.0909\n");
print("  0.4  0.0828\n");
print("  0.5  0.0738\n");
print("  0.6  0.0630\n");
print("  0.7  0.0490\n");
print("  0.8  0.0360\n");
print("  0.9  0.0200\n");
print("  1.0  0.0040\n");
} else {                      // variable pitch
 print("  C_THRUST   11 2\n");
 print("       10      30\n");
 print("  0.0  0.07488 0.0936\n");
 print("  0.1  0.07416 0.0927\n");
 print("  0.2  0.07344 0.0918\n");
 print("  0.3  0.07272 0.0909\n");
 print("  0.4  0.06625 0.0828\n");
 print("  0.5  0.05904 0.0738\n");
 print("  0.6  0.05040 0.0630\n");
 print("  0.7  0.03920 0.0490\n");
 print("  0.8  0.02880 0.0360\n");
 print("  0.9  0.01600 0.0200\n");
 print("  1.0  0.00320 0.0040\n");
}

if($ac_pitch == 0) {          // fixed pitch
print("  C_POWER   11 1\n");
print("  0.0  0.0594\n");
print("  0.1  0.0585\n");
print("  0.2  0.0576\n");
print("  0.3  0.0558\n");
print("  0.4  0.0540\n");
print("  0.5  0.0522\n");
print("  0.6  0.0495\n");
print("  0.7  0.0432\n");
print("  0.8  0.0342\n");
print("  0.9  0.0225\n");
print("  1.0  0.0090\n");
} else {                      // variable pitch
 print("  C_POWER   11 2\n");
 print("       10      30\n");
 print("  0.0  0.02287 0.10395\n");
 print("  0.1  0.02252 0.10237\n");
 print("  0.2  0.02217 0.10080\n");
 print("  0.3  0.02148 0.09765\n");
 print("  0.4  0.02079 0.09450\n");
 print("  0.5  0.02009 0.09135\n");
 print("  0.6  0.01905 0.08662\n");
 print("  0.7  0.01663 0.07560\n");
 print("  0.8  0.01316 0.05985\n");
 print("  0.9  0.00866 0.03937\n");
 print("  1.0  0.00346 0.01575\n");
}

print("</FG_PROPELLER>\n");

?>
